#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<vector<int>> intervals(n,vector<int>(2));
	for(int i=0;i<n;i++){
		cin>>intervals[i][0]>>intervals[i][1];
	}
	
	sort(intervals.begin(), intervals.end(), [](vector<int> u, vector<int> v) {
            return u[1] < v[1];
        });

    int right = intervals[0][1];
    int ans = 1;
    for (int i = 1; i < n; ++i) {
        if (intervals[i][0] >= right) {
            ++ans;
            right = intervals[i][1];
        }
    }
    cout<<n - ans;
    return 0;
}


